function varargout = FisikaGravitasi(varargin)
% FISIKAGRAVITASI MATLAB code for FisikaGravitasi.fig
%      FISIKAGRAVITASI, by itself, creates a new FISIKAGRAVITASI or raises the existing
%      singleton*.
%
%      H = FISIKAGRAVITASI returns the handle to a new FISIKAGRAVITASI or the handle to
%      the existing singleton*.
%
%      FISIKAGRAVITASI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in FISIKAGRAVITASI.M with the given input arguments.
%
%      FISIKAGRAVITASI('Property','Value',...) creates a new FISIKAGRAVITASI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before FisikaGravitasi_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to FisikaGravitasi_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help FisikaGravitasi

% Last Modified by GUIDE v2.5 03-May-2011 17:16:34

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @FisikaGravitasi_OpeningFcn, ...
                   'gui_OutputFcn',  @FisikaGravitasi_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before FisikaGravitasi is made visible.
function FisikaGravitasi_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to FisikaGravitasi (see VARARGIN)

% Choose default command line output for FisikaGravitasi
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes FisikaGravitasi wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = FisikaGravitasi_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


function FisikaGravitasiInput_x_Callback(hObject, eventdata, handles)

function FisikaGravitasiInput_x_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function FisikaGravitasiHitungButton_Callback(hObject, eventdata, handles)
global soal1;
global numsoal;
global metode;
global x0 y0 z0 xr yr zr h n1 n2;
global xn n y01 y02 numy0;
global fxyz1 fxyz2;
global fungsi1 fungsi2;
global numfungsi;
global metodestring;
global hasil1 hasil2;
global numhasil;

cancount = 1;
fxyz1 = @(x,y,z)(z); 
fxyz2 = @(x,y,z)((-2*z-(x*(0.1*y^2)^(3/2)))/x);
x0 = 0.0000001; y0 = 1; z0 = 0;
xr = str2double(get(handles.FisikaGravitasiInput_x,'String'));
h = str2double(get(handles.FisikaGravitasiInput_h,'String'));
metode = get(handles.FisikaGravitasiPopup_metode,'Value');

switch(metode)
    case{1}
        [n1 yr] = Euler(fxyz1,[x0 xr],[y0 z0],h);
        [n2 zr] = Euler(fxyz2,[x0 xr],[y0 z0],h);
        display(yr);
        display(zr);
        metodestring = 'Euler';
    case{2}
        [n1 yr] = Heun(fxyz1,[x0 xr],[y0 z0],h);
        [n2 zr] = Heun(fxyz2,[x0 xr],[y0 z0],h);
        display(yr);
        display(zr);
        metodestring = 'Heun';
    case{3}
        [n1 yr] = Runge_Kutta([x0 xr],h,[y0 z0],fxyz1,3);
        [n2 zr] = Runge_Kutta([x0 xr],h,[y0 z0],fxyz2,3);
        display(yr);
        display(zr);
        metodestring = 'Runge-Kutta Orde 3';
    case{4}
        [n1 yr] = Runge_Kutta([x0 xr],h,[y0 z0],fxyz1,4);
        [n2 zr] = Runge_Kutta([x0 xr],h,[y0 z0],fxyz2,4);
        display(yr);
        display(zr);
        metodestring = 'Runge-Kutta Orde 4';
    case {5}
        n = (xr - x0) / h;
        if (n < 4) 
            cancount = 0;
            msgbox('n yang diperlukan minimal 4. Ubah nilai h atau x');
        else
            [n1 yr] = Adam_Moulton([x0 xr],h,[y0 z0],fxyz1);
            [n2 zr] = Adam_Moulton([x0 xr],h,[y0 z0],fxyz2);
            display(yr);
            display(zr);
            metodestring = 'P-C Adams-Moulton';
        end
end;

if (cancount)
    set(handles.FisikaGravitasiOutput_yx, 'String', num2str(yr(1)));
    set(handles.FisikaGravitasiOutput_yabsenx, 'String', num2str(zr(2)));

    %------------------------------------------------%
    % Pembuatan report
    %------------------------------------------------%
    % Soal
    soal1 = 'xy'''' + 2y'' + x*(0.1*y^2)^3/2 = 0';
    numsoal = 1;
    % Variabel
    % x0 = x0 (variabel dan globalnya sama)
    xn = xr;
    % h = h (variabel dan globalnya sama)
    n = n2;
    y01 = y0; y02 = z0;
    numy0 = 2;
    % Fungsi untuk perhitungan
    fungsi1 = func2str(fxyz1);
    fungsi2 = func2str(fxyz2);
    numfungsi = 2;
    % Hasil
    hasil1 = yr(1);
    hasil2 = zr(2);
    numhasil = 2;
    % Generate Report
    report('DifferentialEquation');
end

function FisikaGravitasiPopup_metode_Callback(hObject, eventdata, handles)

function FisikaGravitasiPopup_metode_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function FisikaGravitasiInput_h_Callback(hObject, eventdata, handles)
% hObject    handle to FisikaGravitasiInput_h (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of FisikaGravitasiInput_h as text
%        str2double(get(hObject,'String')) returns contents of FisikaGravitasiInput_h as a double


% --- Executes during object creation, after setting all properties.
function FisikaGravitasiInput_h_CreateFcn(hObject, eventdata, handles)
% hObject    handle to FisikaGravitasiInput_h (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
